<?php
declare (strict_types=1);

namespace app\api\controller\v1;

use app\api\validate\PapersValidate;
use app\common\model\Major;
use app\common\model\Paper;
use app\common\model\Record;

class Practice
{
    /**
     * 训练中心--模拟考试
     */
    public function index()
    {
        return sucessMsg(200, '获取成功', [
            'practice' => $this->practice(),   //获取模拟考试
        ]);
    }

    /**
     * 训练中心--模拟考试
     */
    public function practice()
    {
        //获取科目
        $data1 = Major::where(['status' => 1])->field('name')->select();

        //获取答题时间
        $data2 = Record::where(['status' => 1])
            ->field('exam_time')
            ->select();
        return ['data1' => $data1, 'data2' => $data2];

    }


    /**
     * 接收试卷名称
     */
    public function create()
    {

        $user = new Paper();
        $data = input();
        try {
            validate(PapersValidate::class)->scene('create')->check($data);
            if ($user->save($data)) {
                return sucessMsg(200, '添加成功！');
            }
            return errMsg(500, '添加失败！');
        } catch (ValidateException $e) {
            return errMsg(400, $e->getError());
        }
    }


}
